package com.suray.wcs.service.pojo.rgv.action;

import com.suray.wcs.service.pojo.rgv.action.util.RgvActionStatus;

public class RgvAction {

    /**
     * 动作序号
     */
    private int actionNo;

    /**
     * 动作状态
     */
    private RgvActionStatus actionStatus;

    /**
     * 动作返回结果
     */
    private int actionResultParam;

    public RgvAction() {
        initStatus();
    }

    public void initStatus() {
        actionStatus = RgvActionStatus.RGV_NONE_ACTION;
        actionNo = 0;
    }

    public int getActionNo() {
        return actionNo;
    }

    public void setActionNo(int actionNo) {
        this.actionNo = actionNo;
    }

    public RgvActionStatus getActionStatus() {
        return actionStatus;
    }

    public boolean isActionDoing() {
        return actionStatus != RgvActionStatus.RGV_NONE_ACTION;
    }

    /**
     *
     * @param actionStatus
     * @return：false 状态设置失败
     */
    public void setActionStatus(RgvActionStatus actionStatus) {

        switch (this.actionStatus) {
            case RGV_NONE_ACTION:
                if (actionStatus == RgvActionStatus.RGV_WAITING_ACTION
                        ||actionStatus == RgvActionStatus.RGV_FAIL_ACTION) {
                    this.actionStatus = actionStatus;
                }
                break;
            case RGV_WAITING_ACTION:
                if (actionStatus == RgvActionStatus.RGV_DOING_ACTION
                        || actionStatus == RgvActionStatus.RGV_END_ACTION
                        || actionStatus == RgvActionStatus.RGV_FAIL_ACTION) {
                    this.actionStatus = actionStatus;
                }
                break;
            case RGV_DOING_ACTION:
                if (actionStatus == RgvActionStatus.RGV_END_ACTION
                        || actionStatus == RgvActionStatus.RGV_FAIL_ACTION) {
                    this.actionStatus = actionStatus;
                }
                break;
            case RGV_END_ACTION:
                if (actionStatus == RgvActionStatus.RGV_NONE_ACTION
                        || actionStatus == RgvActionStatus.RGV_FAIL_ACTION) {
                    this.actionStatus = actionStatus;
                }
                break;
            case RGV_FAIL_ACTION:
                if (actionStatus == RgvActionStatus.RGV_NONE_ACTION) {
                    this.actionStatus = actionStatus;
                }
                break;
            default:
                throw new RuntimeException("当前状态错误" + this.actionStatus);
        }

        if (actionStatus == RgvActionStatus.RGV_END_ACTION) {
            //结束后自动更新为空闲状态
            initStatus();
        }
    }

    public int getActionResultParam() {
        return actionResultParam;
    }

    public void setActionResultParam(int actionResultParam) {
        this.actionResultParam = actionResultParam;
    }

    @Override
    public String toString() {
        return "RgvAction{" +
                "actionNo=" + actionNo +
                ", actionStatus=" + actionStatus +
                ", actionResultParam=" + actionResultParam +
                '}';
    }
}
